<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<jsp:include page="/WEB-INF/common/head.jsp" flush="true" />
<script type="text/javascript" src="${res_url}js/menu.js"></script>
<style type="text/css">
body{
	background-color: #ffffff;
}
.left{
	position: absolute;
	top: 10px;
	left: 20px;
	width: 358px;
	border-right: 1px solid #CCC;
	overflow-y: auto;
}

.tree-menu{
	float: right;
}
.tree-menu span{
	margin-left: 6px;
}
.tree-menu span i{
	cursor: pointer;
}
.icon-plus {
	background-position: -408px -96px;
}
.icon-remove {
	background-position: -312px 0;
}
.icon-edit {
	background-position: -96px -72px;
}
[class^="icon-"], [class*=" icon-"] {
	display: inline-block;
	width: 14px;
	height: 14px;
	line-height: 14px;
	vertical-align: text-top;
	background-image: url("${basePath}res/bootstrap/img/glyphicons-halflings.png");
	background-repeat: no-repeat;
	margin-top: 1px;
}
#menu_tree{
	margin-right: 20px;
}

li{
	line-height: 16px;
}
.om-tree-node a{
	display: inline-block;
	*display: inline;
	*zoom: 1;
	width: 115px;
	overflow: hidden;
	text-overflow: ellipsis;
}
#vip_tip{
	text-align: center;
}
.actions{
	position: absolute;
	bottom: 20px;
	left: 10px;
	width: 368px;
	border-right: 1px solid #CCC;
	height: 60px;
}
</style>
 
	<div class="easyui-layout" id = "main_layout" style="width:100%;height:100%">
	<input id="roleId" type="hidden" value="${roleId}"/>
		<div id="west" class="scrollbar" data-options="region:'west',split:true,collapsedSize:0" title="站点管理"  style="width:400px;">
		<a href="#" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" id="addGroup"  plain="true" onclick="add()" >增加站点目录</a>
        <a href="#" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" id="editGroup" plain="true" onclick="update()">编辑站点目录</a>
        <a href="#" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove"  id="deleteGroup" plain="true" onclick="del()" >删除站点目录</a>
	     	<table id="site"></table>
		</div>
	
		<div data-options="region:'center',title:'对象信息'">
           <!--  <a href="#" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" id="btn-edit" plain="true" onclick="setSite()" >分配站点</a> 
			<table id="dg"></table> -->
		  <div id="mainTabs" style="height:250px">
	        <div title="首页">
	            <iframe src="${context_path}/sys/obj" class="easyui-panel" data-options="fit:true,border:false" frameborder="0"></iframe>
	        </div>
	    </div>
		</div>
		</div>
<script type="text/javascript">
var datagrid = $("#dg");
var siteDatagrid = $("#site");
var zNodes = "";
var treeOnfousId = "";
var treeOnfousType = "";
var grid_selector = "#grid-table";
var pager_selector = "#grid-pager";

var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,
        rownumbers:true,
    	url:'${context_path}/sys/obj/getListData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	multiSort:true,
        queryParams: getInitParam(),
        checkbox:false,
        columns: [[
		          {field:'id', checkbox:true}
	           	 ,{field:'name', title: '名称', width:120, sortable: true}
	           	 ,{field:'link', title: '链接', width:120, sortable: true}
	           	 ,{field:'type', title: '类型', width:250, sortable: true}
	           	 ,{field:'subject', title: '主题', width:100, sortable: true}
	           	 ,{field:'ownName', title: '拥有者', width:100, sortable: true}
	           	 ,{field:'siteName', title: '所属站点', width:100, sortable: true}
	        	 ,{field:'colletc', title: '是否收藏', width:100, sortable: true}
	           	 ,{field:'share', title: '是否共享', width:100, sortable: true}
	           	 ,{field:'userName', title: '分享者', width:100, sortable: true,hidden:'true'}
	           	 ,{field:'shareName', title: '被分享者', width:100, sortable: true,hidden:'true'}
	           ]],
	
	};
	
siteDatagrid.treegrid({
	idField: 'id',
    treeField: 'name',
	rownumbers:true,
	fit:true,
	border:false,
	rownumbers:true,
	url: "${context_path}/sys/site/getAllList",
	method:'get',
	toolbar:'#tb',
	singleSelect:true,
	columns:[[
		{field:'id', checkbox:true},
    	{field:'name', title: '目录名称', width:150},
    	{field:'dirType', title: '目录类型', width:150,hidden:'true'}
    ]],
    loadFilter: function(data) {
    	$.each(data, function(i, item) {
    		if(item.parent_id > 0) {
	    		item._parentId = item.parent_id;
    		}
    	});
    	return {rows: data, total: 0};
    },
	//单击事件   
	onClickRow:function(rowIndex,rowData){
		//获取该站点未分配对象
		if(rowIndex.dirType == 2){
			addMainTab(rowIndex.name,"${context_path}/sys/obj/getNoGiveListView?siteId="+rowIndex.id);
			/* datagrid.datagrid({url:"${context_path}/sys/obj/getNoGiveListData?siteId="+rowIndex.id});
			datagrid.datagrid('hideColumn','userName');
			datagrid.datagrid('hideColumn','shareName'); */
		}else
		//我的对象
		if(rowIndex.dirType == 4){
			addMainTab(rowIndex.name,"${context_path}/sys/obj");
			/* datagrid.datagrid({url:"${context_path}/sys/obj/getListData"});
			datagrid.datagrid('hideColumn','userName');
			datagrid.datagrid('hideColumn','shareName');
			datagrid.datagrid('showColumn','colletc');
			datagrid.datagrid('showColumn','share'); */
		}else
		//我的收藏
		if(rowIndex.dirType == 5){
			addMainTab(rowIndex.name,"${context_path}/sys/objColletc");
	/* 		datagrid.datagrid({url:"${context_path}/sys/objColletc/getCollectObjList"});
			datagrid.datagrid('hideColumn','userName');
			datagrid.datagrid('hideColumn','shareName');
			datagrid.datagrid('hideColumn','colletc');
			datagrid.datagrid('hideColumn','share'); */
		}else
		//别人共享给我的
		if(rowIndex.dirType == 6){
			addMainTab(rowIndex.name,"${context_path}/sys/objShare/getShareObjMeView");
			/* datagrid.datagrid({url:"${context_path}/sys/objShare/getShareMeObjList"});
			datagrid.datagrid('hideColumn','colletc');
			datagrid.datagrid('hideColumn','share');
			datagrid.datagrid('showColumn','userName');
			datagrid.datagrid('showColumn','shareName'); */
		}else
		//我共享给别人的
		if(rowIndex.dirType == 7){
			addMainTab(rowIndex.name,"${context_path}/sys/objShare/getShareObjOtherView");
			/* datagrid.datagrid({url:"${context_path}/sys/objShare/getShareOtherObjList"});
			datagrid.datagrid('hideColumn','colletc');
			datagrid.datagrid('hideColumn','share');
			datagrid.datagrid('showColumn','userName');
			datagrid.datagrid('showColumn','shareName'); */
		}else{
			addMainTab(rowIndex.name,"${context_path}/sys/obj/getPublicObjView?siteId="+rowIndex.id);
		}
		
	
	}
});

function getInitParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();	
		}
	});
	return param;
}
	
	
$(function() {
	datagrid.datagrid(dgOptions);
	siteDatagrid.datagrid(siteDatagrid);
	//权限控制
		var roleId=$("#roleId").val();
	if(roleId!=null&&roleId.indexOf("2")>=0&&roleId.indexOf("1")<0){
		$("#addGroup").hide();
		$("#editGroup").hide();
		$("#deleteGroup").hide();
		$("#btn-edit").hide();
	}			
});
$(document).ready(function(){  
    var height1 = $(window).height()-20;  
    $("#main_layout").attr("style","width:100%;height:"+height1+"px");  
    $("#main_layout").layout("resize",{  
        width:"100%",  
        height:height1+"px"  
    });  
});  
  
$(window).resize(function(){  
    var height1 = $(window).height()-30;  
    $("#main_layout").attr("style","width:100%;height:"+height1+"px");  
    $("#main_layout").layout("resize",{  
        width:"100%",  
        height:height1+"px"  
    });  
});


function add() {
	var rowsSel = siteDatagrid.datagrid("getSelections");
	var id = 0;
	if(rowsSel.length != 1) {
		id = 0
	}else{
		var id = rowsSel[0].id;
	}
	
	if(rowsSel[0].dirType !=1) {
		showWarnMsg("请选择公共目录进行目录管理");
		return;
	}else{
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("增加成功！");
		siteDatagrid.treegrid("load");
	}
	top.openWindow("站点管理-增加站点", '${context_path}/sys/site/add?pid='+id, {size: '600x400'});
	}
}

function update() {
	
	var rowsSel = siteDatagrid.datagrid("getSelections");
	
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	if(rowsSel[0].dirType !=1) {
		showWarnMsg("请选择公共目录进行目录管理");
		return;
	}else{
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功！");
		siteDatagrid.treegrid("load");
	}
	top.openWindow("对象管理-编辑", '${context_path}/sys/site/add?gid=' + id, {size: '600x400'});
	}
}

function del() {
	
	var rowsSel = siteDatagrid.datagrid("getSelections");
	
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	if(rowsSel[0].dirType !=1) {
		showWarnMsg("请选择公共目录进行目录管理");
		return;
	}else{
	var id = rowsSel[0].id;
	
	confirmMsg("确认删除？", function() {
		$.post("${context_path}/sys/site/delete", {"ids": id}, function(data) {
			if(data.code = 0){
				showMsg("删除成功")
			}else{
				showMsg(data.msg);	
			}
			
			siteDatagrid.treegrid("reload");
		});
	});
	}
}



//按钮事件

/**
 * 打开子页
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

function forword(url){
	window.location.href=url;
}

//对象操作相关

//站点分配
function setSite() {
	var ids = "";
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids = ids+item.id+",";
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要分配的数据！");
		return;
	}
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("分配成功！");
		datagrid.datagrid("reload");
	}
	top.openWindow("站点分配", '${context_path}/sys/site/setSiteView?oid=' + ids, {size: '600x400'});
}
//删除对象
function removeSite() {
	var ids = "";
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids = ids+item.id+",";
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据！");
		return;
	}
	confirmMsg("确认删除？", function() {
		$.post("${context_path}/sys/obj/delete", {"ids": ids}, function(data) {
			showMsg("删除成功！");
			datagrid.datagrid("reload");
		});
	});
}


/**
 * 增加一个主窗口
 */
function addMainTab(text, url) {
	if(!mainTabs.tabs("exists", text)) {
		mainTabs.tabs('add',{
            title: text,
            content:'<iframe src="' + url + '" class="easyui-panel" data-options="fit:true,border:false" frameborder="0"></iframe>',
            closable:true
        });
    }else {
    	mainTabs.tabs("select", text);
    	//刷新
    	mainTabs.tabs('getSelected').panel('panel').find('iframe').attr("src", url)
    }
}

//扩展js
</script>
  <jsp:include page="/WEB-INF/common/dialogWindow.jsp" flush="true" />
   <jsp:include page="/WEB-INF/common/foot.jsp" flush="true" />